<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-wms__station}">
      <wms-form 
        v-model="dataForm"
        :formList="formList"
        :table-column="tableColumn"
        :advanced="advanced"
        @check-change="checkChange"
        @changeAdvance="changeAdvance"
        @getDataList="getDataList"
        @getReset="getReset"
      >
      </wms-form>
      <wms-table
        ref="wmsTable"
        v-model="dataForm"
        :page="page"
        :total="total"
        :limit="limit"
        :tableData="dataList"
        :table-column="column"
        :module-options="mixinViewModuleOptions"
        :dataListLoading="dataListLoading"
        @changeStation="changeStation"
        @pageSizeChangeHandle="pageSizeChangeHandle"
        @pageCurrentChangeHandle="pageCurrentChangeHandle"/>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from "@/mixins/view-module";
import AddOrUpdate from "./components/station-add-or-update";
import debounce from "lodash/debounce";
import { formList, tableColumn } from './config'
import wmsTable from '@/components/wms-table'
import wmsForm from '@/components/wms-form'
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: "/wms/station/page",
        getDataListIsPage: true,
        exportURL: "/wms/station/export",
        deleteURL: "/wms/station",
        deleteIsBatch: true,
        deleteIsBatchKey:'stationId'
      },
      dataForm: {
        stationNo : '',
        stationSt: ''
      },
      formList,
      tableColumn,
      column: [],
      advanced: false,
      changeForm: {
        stationId: '',
        stationSt: ''
      },
    };
  },
  components: {
    AddOrUpdate,
    wmsTable,
    wmsForm
  },
  methods: {
    //0.重置搜索框
    getReset() {
      this.dataForm = this.$options.data().dataForm;
    },
    //1.库存冻结
    changeStation: debounce(function (val, row) {
      var tempStatus = row.stationSt === 0 ? 1 : 0;
      this.changeForm.stationId = row.stationId;
      this.changeForm.stationSt = row.stationSt;
      this.$http[!this.changeForm.stationId ? 'post' : 'put']('/wms/station/', this.changeForm).then(({ data: res }) => {
        if (res.code !== 0) {
          //如果更新失败则重置为原来的状态
          row.stationSt = tempStatus;
          return this.$message.error(res.msg)
        }
        if (this.changeForm.stationSt === 1) {
          this.$message({
            message: '站台已禁用',
            type: 'success',
            duration: 1000,
            onClose: () => {
            }
          })
        }
        if (this.changeForm.stationSt === 0) {
          this.$message({
            message: '站台解禁成功',
            type: 'success',
            duration: 1000,
            onClose: () => {
            }
          })
        }
      }).catch(() => { })
    }),
  },
};
</script>
<style>
.right-handle-group {
  float: right;
}
</style>


